window._CU = {

    _UNITNMB:[
		{nmb:1000000000000000000000000,label:'亿亿亿'},
		{nmb:100000000000000000000,label:'万亿亿'},
		{nmb:10000000000000000,label:'亿亿'},
		{nmb:1000000000000,label:'万亿'},
		{nmb:100000000,label:'亿'},
		{nmb:10000,label:'万'}
	],
	
	getUnitNmb:function(nmb){

        var isfushu = nmb<0;

        if(isfushu)
            nmb=nmb/1*(-1);
		
		for(var i=0;i<_CU._UNITNMB.length;i++){
			
			if(nmb>_CU._UNITNMB[i].nmb){
				
				return (nmb/_CU._UNITNMB[i].nmb).toFixed(2)+_CU._UNITNMB[i].label;
				
			}
			
		}
		
        if(isfushu){
            return "-"+nmb;
        }else{
		    return nmb;
        }
		
	},

    //获取节点距离
    getPosDis:function(x,y,tx,ty){

        return Math.abs(x-tx)+Math.abs(y-ty);

    },

    //判断两个坐标是否相邻
    isPosNear:function(pos1,pos2){

        if(pos1.x==pos2.x&&pos1.y==pos2.y){
            return true;
        }

        if(pos1.x==pos2.x){
            return Math.abs(pos1.y-pos2.y)==1;
        }else if(pos1.y==pos2.y){
            return Math.abs(pos1.x-pos2.x)==1;
        }

        return false;

    },

    getPlayerDis:function(player,target){
        if(player.chessPos&&target.chessPos){
            return _CU.getPosDis(player.chessPos.x,player.chessPos.y,
                                    target.chessPos.x,target.chessPos.y);
        }

        return 999;
    },

    playBgm:function(bgmname,audioBgArr){
		
		for(var i=0;i<audioBgArr.length;i++){
			
			if(audioBgArr[i].name == bgmname){
				
				cc.audioEngine.play(audioBgArr[i], false, 1);
				
				break;
				
			}
			
		}
		
	},


    initAllAniNode:function(pf,node){

        var aniObj = _GRM.getAttackFrame(pf);
        var aniArr = [].concat(aniObj.walk).concat(aniObj.walk)
                    .concat(aniObj.attack).concat(aniObj.attack)
                    .concat(aniObj.weak).concat(aniObj.weak);
        node.getComponent(cc.Animation).addClip(_GRM.createAniClipTime(aniArr,'walk',cc.WrapMode.Loop,8));
        node.getComponent(cc.Animation).play('walk');

    },

    //获取最大页数
    getLastPage:function(total,pagesize){

        var lastPage = 0;
        if(total>pagesize){
            lastPage=total%pagesize>0?
                    Math.floor(total/pagesize):
                    (Math.floor(total/pagesize)-1)
                    ;
        }     
        return lastPage;
    },

    //获取数组中相对最小下标
    getLevelOfArr:function(arr,data){

        for(var i=arr.length-1;i>=0;i--){
            if(data>=arr[i])
                return i;
        }

        return 0;

    },

    
    like:function(str1,str2){
        var result = str2.indexOf(str1);
        if(result<0){
            return false;
        }else{
            return true;
        }
    },

    //数组重是否包含
    isContain:function(arr,obj){

        if(!arr||!obj)
            return false;

        for(var i=0;i<arr.length;i++){
            if(arr[i]==obj)
                return true;
        }

        return false;
    },

    //向下取整
    floor:function(nmb){
        return Math.floor(nmb);
    },

    //随机数
    random:function(nmb){
        return Math.floor(Math.random()*nmb);
    },

    //随机数组元素
    randomObj:function(arr){
        if(arr&&arr.length>0)
        return arr[_CU.random(arr.length)];
        return null;
    },

    /*
    //判断角色对象是否相等
    isSamePlayer:function(playerA,playerB){

        if(!playerA||!playerB)
            return false;

        return playerA.isplayer==playerB.isplayer
                &&playerA.teamIndex==playerB.teamIndex;

    },*/

    //按名字给数组元素减一
    cutArrNmb:function(arr,type){
        if(arr&&type&&arr.length>0){
            for(var i=0;i<arr.length;i++){
                if(arr[i]&&arr[i].type == type){
                    if(arr[i].nmb>1){
                        arr[i].nmb--;
                    }else{
                        arr.splice(i,1);
                    }
                    break;
                }
            }
        }

    },

    //通用关闭界面事件
    cancelFunc:function(){
		_GRM.putNode(this);
	},

    //复制对象
    cloneObj:function(source){
        if(source){
		    return JSON.parse(JSON.stringify(source));
        }
        return null;
	},

    sin:function(arc){
        return Math.sin(arc * Math.PI / 180);
    },

    cos:function(arc){
        return Math.cos(arc * Math.PI / 180);
    },

    getDataDraw:function(data){
        if(data>_MRDL.maxlength)
            return _MRDL.maxlength;
        return data;
    },

    //绘制五位图
    drawData:function(graphics,dataArr,per){

        console.log('五维比例',per);

        graphics.clear();

		graphics.strokeColor.fromHEX('#00ff00');
		graphics.strokeColor.a = 0;

        graphics.moveTo(0,0);
		graphics.lineTo(0,_CU.getDataDraw(dataArr[0])*per);
        graphics.lineTo(_CU.getDataDraw(dataArr[1])*_CU.cos(18)*per,_CU.getDataDraw(dataArr[1])*_CU.sin(18)*per);
        graphics.lineTo(_CU.getDataDraw(dataArr[2])*_CU.cos(54)*per,-_CU.getDataDraw(dataArr[2])*_CU.sin(54)*per);
        graphics.lineTo(-_CU.getDataDraw(dataArr[3])*_CU.sin(36)*per,-_CU.getDataDraw(dataArr[3])*_CU.cos(36)*per);
        graphics.lineTo(-_CU.getDataDraw(dataArr[4])*_CU.cos(18)*per,_CU.getDataDraw(dataArr[4])*_CU.sin(18)*per);
		graphics.lineTo(0,_CU.getDataDraw(dataArr[0])*per);
		graphics.moveTo(0,0);
		graphics.fillColor.fromHEX('#00ff00');
		graphics.fillColor.a = 125;
		graphics.fill();
		graphics.stroke();

    },

    isSamePlayer:function(a,b){

        return  a
                &&b
                &&a.chessPos
                &&b.chessPos
                &&a.chessPos.x==b.chessPos.x
                &&a.chessPos.y==b.chessPos.y

    },

    getArrObjByOrder:function(index,arr){

        if((index+1)%5==0){
            var bossIndex = Math.floor((index+1)/5-1)%arr.length;
            return arr[bossIndex];
        }

        return null;

    },

    isObjEmpty:function(obj){

        if(!obj){
            return true;
        }

        for(var key in obj){
            return false;
        }

        return true;

    },

    randomXwValue:function(min,max,addlv){
        return Math.floor((min+Math.random()*(max-min))*addlv*10)/10;
    },

    objToArr:function(obj){
        if(obj){
            var arr=[];
            for(var key in obj){
                arr.push(key);
            }
            return arr;
        }
        return null;
    },
}